package com.cskaoyan.utils;

import com.cskaoyan.exception.ValidationException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

public class ValidationUtil {
    public static void valid(BindingResult bindingResult) {
        if (bindingResult.hasErrors()){
            FieldError fieldError = bindingResult.getFieldError();
            String field = fieldError.getField();
            Object rejectedValue = fieldError.getRejectedValue();
            String defaultMessage = fieldError.getDefaultMessage();
            String message = field + defaultMessage;
            throw new ValidationException(message);
        }
    }
}
